When highlighting, Color QuickDraw replaces the background color with the highlight color when your application draws or copies images between graphics ports. This has the visual effect of using a highlighting pen to select the object. For instance, TextEdit (described in Inside Macintosh: Text ) uses highlighting to indicated selected text; if the highlight color is yellow, TextEdit draws the selected text, then uses InvertRgn to produce a yellow background for the text.
With basic QuickDraw, you can use InvertRect , InvertRgn , InvertArc , InvertRoundRect , or InvertPoly and any image-copying routine that uses the srcXor source mode to invert objects on the screen.
In general, however, you should use highlighting with Color QuickDraw when selecting and deselecting objects such as text or graphics. (Highlighting has no effect in basic QuickDraw.) The line reading "hilited" in Figure 4-15 uses highlighting; the user selected red as the highlight color, which the application uses as the background for the text. (This figure shows the effect in grayscale.) The application simply inverts the background for the line reading "inverted." Inversion reverses the colors of all pixels within the rectangle's boundary. On a black-and-white monitor, this changes all black pixels in the shape to white, and changes all white pixels to black. Although this procedure operates on color pixels in color graphics ports, the results are predictable only with direct pixels or 1-bit pixel maps.
Figure 15 Difference between highlighting and inverting
The global variable HiliteRGB is read from parameter RAM when the machine starts. Basic graphics ports use the color stored in the HiliteRGB global variable as the highlight color. Color graphics ports default to the HiliteRGB global variable, but you can override this by using the HiliteColor procedure, described on HiliteColor .
To turn highlighting on when using Color QuickDraw, you can clear the highlight bit just before calling InvertRect , InvertRgn , InvertArc , InvertRoundRect , InvertPoly , or any drawing or image-copying routine that uses the patXor or srcXor transfer mode. On a bitmap or a 1-bit pixel map, this works exactly like inversion and is compatible with all versions of QuickDraw.
The following constant represents the highlight bit:
CONST pHiliteBit = 0; {flag bit in HiliteMode used with BitClr}
You can use the BitClr procedure as shown in Listing 4-6 to clear system software's highlight bit ( BitClr is described in Inside Macintosh: Operating System Utilities ).
Listing 6 Setting the highlight bit
PROCEDURE MySetHiliteMode;
BEGIN
BitClr(Ptr(HiliteMode), pHiliteBit);
END;
Listing 4-7 shows the code that produced the effects in Figure 4-15 .
Listing 7 Using highlighting for text
PROCEDURE HiliteDemonstration (window: WindowPtr);
CONST
s1 = ' hilited ';
s2 = ' inverted ';
VAR
familyID: Integer;
r1, r2: Rect;
info: FontInfo;
bg: RGBColor;
BEGIN
TextSize(48);
GetFontInfo(info);
SetRect(r1, 0, 0, StringWidth(s1), info.ascent + info.descent);
SetRect(r2, 0, 0, StringWidth(s2), info.ascent + info.descent);
OffsetRect(r1, 30, 20);
OffsetRect(r2, 30, 100);
{fill the background with a light-blue color}
bg.red := $A000;
bg.green := $FFFF;
bg.blue := $E000;
RGBBackColor(bg);
EraseRect(window^.portRect);
{draw the string to highlight}
MoveTo(r1.left + 2, r1.bottom - info.descent);
DrawString(s1);
MySetHiliteMode; {clear the highlight bit}
{InvertRect replaces pixels in background color with the }
{ user-specified highlight color}
InvertRect(r1);
{the highlight bit is reset automatically}
{show inverted text, for comparison}
MoveTo(r2.left + 2, r2.bottom - info.descent);
DrawString(s2);
InvertRect(r2);
END;
Color QuickDraw resets the highlight bit after performing each drawing operation, so your application should always clear the highlight bit immediately before calling a routine with which you want to use highlighting.
Another way to use highlighting is to add this constant or its value to the mode you specify to the PenMode , CopyBits , CopyDeepMask , and TextMode routines:
CONST hilite = 50; {add to source or pattern mode for highlighting}
Highlighting uses the pattern or source image to decide which bits to exchange; only bits that are on in the pattern or source image can be highlighted in the destination.
A very small selection should probably not use highlighting, because it might be too hard to see the selection in the highlight color. TextEdit, for instance, uses highlighting to select and deselect text, but not to highlight the insertion point.
Highlighting is optimized to look for consecutive pixels in either the highlight or background colors. For example, if the source is an all-black pattern, the highlighting is especially fast, operating internally on one long word at a time instead of one pixel at a time. Highlighting a large area without such consecutive pixels (a gray pattern, for instance) can be slow.